package com.gs.api.util.video.parse;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * @author guoyunfei on 2022/3/12 11:52
 * @className ImageParse
 * @description TODO
 * @Version 1.0
 */
public class ImageParse {

    /**
     * 抖音图集
     */
    public static List<String> douYinParseData(JSONObject obj) {
        List<String> list = Lists.newArrayList();
        try {
            // 获取当前的图集的真实url
            JSONArray jsonArray = obj.getJSONArray("item_list").getJSONObject(0).getJSONArray("images");

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject imageObj = jsonArray.getJSONObject(i);
                JSONArray url_list = imageObj.getJSONArray("url_list");
                list.add(url_list.get(0).toString());
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 快手图集
     * @param obj
     */
    public static List<String> kuaiShouParseUrl(JSONObject obj) {
        List<String> list = Lists.newArrayList();

        // 获取当前视频信息
        JSONObject video = obj.getJSONObject("video");

        String imageCDN = video.getString("imageCDN");

        JSONArray images = video.getJSONArray("images");
        for (int i = 0; i < images.size(); i++) {
            list.add(ParseConstant.HTTPS + imageCDN + images.getJSONObject(i).getString("path"));
        }
        return list;
    }




}
